﻿using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Smatime.Web.DAO;
using Smatime.Web.Models;

namespace Smatime.Web.Controllers
{
    public class CompanyController : ApiController
    {
        // GET api/company
        public IEnumerable<Company> Get()
        {
            return new CompanyRepository().GetList();
        }

        // GET api/company/5
        public Company Get(int id)
        {
            return new CompanyRepository().GetById(id);
        }

        // GET api/company/useraccess/1
        [Route("api/company/useraccess/{id}")]
        public IEnumerable<Company> GetCompamyId(int id)
        {
            return new CompanyRepository().GetCompanyByUserId(id);
        }

        // POST api/company
        public HttpResponseMessage Post([FromBody] Company value)
        {
            try
            {
                var repos = new CompanyRepository();
                repos.Insert(value);
                return Request.CreateResponse(HttpStatusCode.OK);
            }
            catch (Exception)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
        }

        // PUT api/company/5
        public void Put(int id, [FromBody] Company value)
        {
            var repos = new CompanyRepository();
            value.Id = id;
            repos.Update(value);
        }

        // DELETE api/company/5
        public void Delete(int id)
        {
        }
    }
}